﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TPAdministracion.Ayudas;
using TPAdministracion.ws;

namespace TPAdministracion.Forms
{
    public partial class ProveedorAgregarModificar : Form
    {
        private bool EsInsertar = false;

        public ProveedorAgregarModificar()
        {
            InitializeComponent();
            this.EsInsertar = true;
            
        }
        public ProveedorAgregarModificar(ws.proveedor prov)
        {
            InitializeComponent();
            this.tbUser.Text = prov.usuario;
            this.tbUser.Enabled = false;
            this.tbPass.Text = prov.pass;
            this.tbEmail.Text = prov.email;
            this.tbPais.Text = prov.pais;
            this.tbDirec.Text = prov.direccion;
            this.tbRazon.Text = prov.razonSocial;
         
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.EsInsertar)
            {
                ws.proveedor prov = new ws.proveedor();
                prov.usuario = this.tbUser.Text;
                prov.pass = this.tbPass.Text;
                prov.email = this.tbEmail.Text;
                prov.pais = this.tbPais.Text;
                prov.direccion = this.tbDirec.Text;
                prov.razonSocial = this.tbRazon.Text;


                ws.AdministradorWSClient crearprovedor = new AdministradorWSClient();
                crearprovedor.createProveedor(prov);

                MessageBox.Show("Proveedor creado correctamente", "OK", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                tbDirec.ResetText();
                tbEmail.ResetText();
                tbPais.ResetText();
                tbPass.ResetText();
                tbRazon.ResetText();
                tbUser.ResetText();
        

                

            }
            else
            {
                ws.proveedor prov = new ws.proveedor();
                prov.usuario = this.tbUser.Text;
                prov.pass = this.tbPass.Text;
                prov.email = this.tbEmail.Text;
                prov.pais = this.tbPais.Text;
                prov.direccion = this.tbDirec.Text;
                prov.razonSocial = this.tbRazon.Text;

                ws.AdministradorWSClient modifprov = new AdministradorWSClient();
                modifprov.editProveedor(prov);
                MessageBox.Show("Proveedor modificado correctamente", "OK", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                this.Close();


            }
        }

        private void btnCancelar_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
    }
}
